<?php

/**
 * Registration form.
 *
 * @subpackage form
 * @author     Sibers
 */
class registrationForm extends sfGuardUserForm {

    /**
     *  Configuration of form fields
     */
    public function configure() {
        parent::configure();
        $this->removeFields();

        // Set Widgets
        
        
        $this->widgetSchema['username'] = new sfWidgetFormInputText();
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['password_confirmation'] = new sfWidgetFormInputPassword();
        $this->widgetSchema['email_address'] = new sfWidgetFormInputText();
        
        //$this->widgetSchema['captcha'] = new sfWidgetFormInputText();
        // Set Labels
        $this->widgetSchema->setLabels(array(
            'password_confirmation' => 'Повторите пароль: <span class="req">*</span>',
            'password' => 'Пароль: <span class="req">*</span>',
            'username' => 'Юзернейм: <span class="req">*</span>',
            'email_address' => 'И-мэил: <span class="req">*</span>',
        ));

        $this->widgetSchema->setPositions(array(
            'username',
            'password',
            'password_confirmation',
            'email_address'
        ));

        
        $this->validatorSchema->setOption('allow_extra_fields', true);
        $this->validatorSchema->setOption('filter_extra_fields', false);

        
        //$this->validatorSchema['captcha'] = new validatorCaptcha(array('required' => true));
        $this->validatorSchema['username'] = new sfValidatorString(array('required' => true, 'min_length' => 4, 'max_length' => 20), array('required' => 'Это поле не может быть пустым','min_length' => 'Юзернейм должен быть не менне 4 символов.', 'max_length' => 'Юзернейм должен быть больше 20 символов'));
        $this->validatorSchema['email_address'] = new sfValidatorEmail(array('required' => true),  array('invalid' => 'Адрес электронной почты указан не верно', 'required' => 'Это поле не может быть пустым'));
        $this->validatorSchema['password'] = new sfValidatorString(array('required' => true, 'min_length' => 4, 'max_length' => 20),
                array('min_length' => 'Пароль должен быть не менне 4 символов.', 'max_length' => 'Пароль должен быть больше 20 символов','required' => 'Это поле не может быть пустым'));
        $this->validatorSchema['password_confirmation'] = clone $this->validatorSchema['password'];
        $this->mergePostValidator(new sfValidatorSchemaCompare('password',
                        sfValidatorSchemaCompare::EQUAL, 'password_confirmation',
                        array(),
                        array('invalid' => 'Ну пароли как бы должны совподать ;)')));
        //$this->widgetSchema->setNameFormat('transferPayment[%s]');
        
    }

    /**
     *  Unsetting some form fields
     */
    protected function removeFields() {
        unset(
                $this['id'],
                $this['username'],
                $this['email_address'],
                $this['algorithm'],
                $this['salt'],
                $this['is_super_admin'],
                $this['last_login'],
                $this['is_active'],
                $this['created_at'],
                $this['updated_at'],
                $this['groups_list'],
                $this['permissions_list'],
                $this['account_type'],
                $this['account_status'],
                $this['referral_id'],
                $this['last_online'],
                $this['first_name'],
                $this['last_name'],
                $this['question1'],
                $this['question2'],
                $this['company'],
                $this['link'],
                $this['logged'],
                $this['is_cancel'],
                $this['suspend_count'],
                $this['token']
        );
    }

}
